# -*- coding: UTF-8 -*-
'''
@Project ：pythonProject 
@File    ：dictDemo3.py
@Author  ：jujuwei
@Date    ：2023/9/28 17:24 
'''
# 字典的基本操作：key的判断、删除、清空、新增、修改

# 字典key的判断：in或者not in,返回布尔值ture或者false
dict1 = dict(name='张三', age=18, gender='男', address='北京')
print(dict1)
print('name' in dict1)
print('name' not in dict1)

# 字典的删除：del或者clear
# 1.del删除指定的键值对
del dict1['name']
print(dict1)

# 2.del删除整个字典
del dict1
# print(dict1)    # 字典不存在时，会报错NameError: name 'dict1' is not defined

# 3.clear清空字典
dict2 = dict(name='李四', age=20, gender='女', address='上海')
dict2.clear()
print(dict2)    # 字典执行clear()方法后，字典中的所有元素都会被删除

# 字典的新增和修改
dict2['phone'] = '123456'
print(dict2)

dict2['phone'] = '1234567890'
print(dict2)



